package com.bestv.search.common.dao.hibernate;

import com.bestv.search.common.dao.EntranceDao;
import com.bestv.search.common.model.Entrance;

import java.util.List;

public class EntranceDaoHibernate extends GenericDaoHibernate<Entrance, Long> implements EntranceDao {

    public EntranceDaoHibernate() {
        super(Entrance.class);
    }

    public Entrance getEntranceById(Long id) {
        return super.get(id);
    }

    public List<Entrance> getEntrances() {
        return super.getAll();
    }

    public Entrance saveEntrance(Entrance entrance) {
        return super.save(entrance);
    }

    @SuppressWarnings("unchecked")
    public Entrance getEntranceByUrl(String url) {
        List<Entrance> list = getHibernateTemplate().find("from Entrance e where e.url = ?", url);
        if (list == null || list.size() == 0)
            return null;
        return list.get(0);
    }

    @SuppressWarnings("unchecked")
    public List<Entrance> getComms(String typename) {
        return getHibernateTemplate().find("from Entrance e where e.subType.name = ?", typename);
    }
}
